package com.clouds.wms.cms;

import java.io.PrintWriter;
import java.util.List;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import net.sf.json.JSONObject;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import com.clouds.wms.bean.Cmsmg;
import com.clouds.wms.exception.SysException;
import com.clouds.wms.service.CmsmgService;
import com.clouds.wms.util.RequestHelper;

@Controller
@RequestMapping("/cmsmg")
public class CmsmgController {

	private Log log = LogFactory.getLog(getClass());
	
	@Resource(name="cmsmgService")
	private CmsmgService cmsmgService;

	/**
	 * 列出所有的角色
	 * @param request
	 * @param response
	 * @return
	 * @throws SysException
	 */
	@RequestMapping(value = "/cmsmgList.xhtml")
	public String cmsmgList(HttpServletRequest request, HttpServletResponse response, Model model) throws SysException {
		String mbaa = RequestHelper.getString(request, "mbaa");
		List<Cmsmg> list = cmsmgService.getCmsmgListByMbaa(mbaa);
		response.setContentType("text/xml;charset=utf-8");
		response.setHeader("Pragma", "No-cache");
		response.setDateHeader("Expires", 0);
		response.setHeader("Cache-Control", "no-cache");
		PrintWriter out = null;
		String callback = request.getParameter("callback");
		try {
			out = response.getWriter();
			JSONObject datas = new JSONObject();
			datas.put("data", list);
			out.write(callback + "(" + datas.toString() + ");");
		} catch (Exception e) {
			log.error(e.getMessage());
		}
		return null;
	}

}
